# coding=utf-8
from django.contrib import admin
# from django.contrib.contenttypes.admin import GenericTabularInline
from apps.product.models import Product
from apps.product.models import ProductCityRelation
from apps.product.models import ProductApiProduct
from apps.order.models import PriceUpdate


# class PriceInline(admin.TabularInline):
#     model = PriceUpdate
#     # max_num = 20
#     extra = 1  # 用于添加外键关系模型的空行
#     # verbose_name = '类别属性'  # 外键关系模型列表最下面的添加另外一个***,所用的名字
#     # show_change_link = True  # 显示修改连接,这个很有用啊!!!!
#     can_delete = True  # 是否显示删除框
#     # exclude = ['create_sub_button_key_option']
#
#
class ProductCityInline(admin.TabularInline):
    model = ProductCityRelation
    # max_num = 20
    # extra = 1  # 用于添加外键关系模型的空行
    # verbose_name = '类别属性'  # 外键关系模型列表最下面的添加另外一个***,所用的名字
    # # show_change_link = True  # 显示修改连接,这个很有用啊!!!!
    # can_delete = True  # 是否显示删除框
    # exclude = ['create_sub_button_key_option']


class ProductAdmin(admin.ModelAdmin):
    # inlines = [ProductCityInline, ]  # Inline
    list_display = ("id", 'name', "type", "order", "price_type_desc")
    #
    list_per_page = 50
    #
    list_filter = ("type", "name",)

    def price_type_desc(self, model):
        return model.get_price_type_display()

    price_type_desc.short_description = "佣金类型"


#
#
# class ProductApiProductAdmin(admin.ModelAdmin):
#     list_display = ("product_name", "company", "api_product")
#
#     def product_name(self, model):
#         return model.product.name
#
#     product_name.short_description = "产品名称"
#
#

class ProductCityRelationAdmin(admin.ModelAdmin):
    list_display = ("product_name", "province_name", "city_name")

    def product_name(self, model):
        return model.product.name

    def province_name(self, model):
        return model.province.name

    def city_name(self, model):
        return model.city.name

    product_name.short_description = "产品名称"
    province_name.short_description = "省份"
    city_name.short_description = "城市"


admin.site.register(Product, ProductAdmin)
admin.site.register(ProductCityRelation, ProductCityRelationAdmin)
# admin.site.register(ProductApiProduct, ProductApiProductAdmin)
